package com.baozun.houji.goods.network

import com.baozhun.mall.common.model.bean.*
import com.baozhun.mall.common.network.NetworkApi
import com.baozun.houji.goods.model.bean.*
import me.hgj.jetpackmvvm.network.BaseResponse
import retrofit2.http.*

/**
 * @Title：首页ApiService
 * @Description：
 * @Author：xuefeng.zhu
 * @Since：2022/11/4
 * @Version：1.0.0
 */
interface HomeApiService {
    /**
     * 登录
     */
    @FormUrlEncoded
    @POST("/mock/29221/user/login")
    suspend fun login(
        @Field("username") username: String, @Field("password") pwd: String
    ): ApiResponse<UserInfo>


    /**
     * 获取商品数据
     */
    @GET("goods/get")
    suspend fun getGoodsInfo(
        @Query("id") goodsId: String,
        @Query("goods_type") goodsType: String?,
        @Query("os") source: String = "android"
    ): ApiResponse<GoodsInfoBean>

    /**
     * 获取推荐商品数据
     */
    @GET("goods/getChannelGoodsRecommend")
    suspend fun getRecommendGoodsInfo(
        @Query("goods_id") goodsId: String,
        @Query("goods_type") goodsType: String?,
    ): ApiResponse<GoodsInfoBean>

    /**
     * 分类列表数据
     */
    @GET("index/getDataByChannelId")
    suspend fun getCategoryGoodsData(
        @Query("id") id: String,
        @Query("sort") sort: Int?,
        @Query("sort_order") sortOrder: Int?,
        @Query("page") page: Int,
        @Query("updated_at") updatedAt: String? = null,
    ): ApiResponse<ApiPagerResponse<ArrayList<GoodsInfoBean>>>


    /**
     * 获取推荐数据
     */
    @GET("index/data")
    suspend fun getSearchRecommend(): BaseResponse<List<GoodsInfoBean>>


    /**
     * 获取推荐数据
     */
    @GET("index/data")
    suspend fun getSearchAssociative(@Query("keywords") keywords: String): BaseResponse<MutableList<String>>

    /**
     * 搜索
     * search_type:1:淘宝/天猫 2:京东 3:自营
     * sort_order:升降类型 2:降序 非2为升序
     */
    @GET("goods/search")
    suspend fun search(
        @QueryMap params: HashMap<String, String>
    ): ApiResponse<ApiPagerResponse<List<GoodsInfoBean>>>
    /**
     * 获取金刚位数据
     */
    @GET("index/getHomeGoldenData")
    suspend fun getHomeGoldenData(): ApiResponse<ArrayList<HomeGoldenBean>>

}

/**
 * 双重校验锁式-单例 封装NetApiService 方便直接快速调用简单的接口
 */
val homeApiService: HomeApiService by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
    NetworkApi.INSTANCE.getApi(HomeApiService::class.java, NetworkApi.Companion.SERVER_URL)
}